﻿using LCL.Config;
using LCL.LData;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace LCL.DbSqlMonitor
{
    public interface ISQLMonitor
    {
        DbConfigInfo DbConfig { get; set; }
        bool DbLinkTest();
        int RowNum { get; set; }
        DataTable GetSqlALL();
        bool Clear();
    }

    internal class DBMonitorFactory
    {
        internal static ISQLMonitor CreateDBMonitor(DbConfigInfo _dbConfig)
        {
            ISQLMonitor result=null;
            try
            {
                switch (_dbConfig.DbType)
                {
                    case LDbType.MySQL:
                        result = new MySQLImpl(_dbConfig);
                        break;
                    case LDbType.SQLServerCe:
                    case LDbType.SQLServer:
                        result = new SQLServerImpl(_dbConfig);
                        break;
                    case LDbType.Oracle:
                        result = new OracleImpl(_dbConfig);
                        break;
                    case LDbType.SQLite:
                        break;
                    case LDbType.ODBC:
                        break;
                    case LDbType.OleDb:
                        break;
                    case LDbType.MongoDB:
                        break;
                }
            }
            catch(Exception ex)
            {
                Logger.Exception("SQLMonitor", "CreateDBMonitor", ex);
                MessageBox.Show("配置文件不正确，无法加载对应的数据库的适配器！");
                Environment.Exit(0);
                result = null;
            }
            return result;
        }
    }
}
